package top.ruanlitao.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ruanlitao.shortlink.project.common.convention.result.Result;
import top.ruanlitao.shortlink.project.common.convention.result.Results;
import top.ruanlitao.shortlink.project.dto.req.ShortLinkStatsAccessRecordReqDTO;
import top.ruanlitao.shortlink.project.dto.req.ShortLinkStatsReqDTO;
import top.ruanlitao.shortlink.project.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import top.ruanlitao.shortlink.project.dto.resp.ShortLinkStatsRespDTO;
import top.ruanlitao.shortlink.project.service.ShortLinkStatsService;

@RestController
@RequestMapping("/api/short-link/v1")
@RequiredArgsConstructor
public class ShortLinkStatsController {

    private final ShortLinkStatsService shortLinkStatsService;

    /**
     * 查询一条短链接在指定时间内的访问数据
     */
    @GetMapping("/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam) {
        requestParam.setEnableStatus(requestParam.getEnableStatus() == null ? 0 : requestParam.getEnableStatus());
        return Results.success(shortLinkStatsService.oneShortLinkStats(requestParam));
    }

    /**
     * 查询一条短链接在指定时间内的历史记录
     */
    @GetMapping("/stats/access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
        requestParam.setEnableStatus(requestParam.getEnableStatus() == null ? 0 : requestParam.getEnableStatus());
        return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(requestParam));
    }
}
